package com.imooc.springboot.dubbo.nilinili.consumer.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.imooc.springboot.dubbo.nilinili.res.CodeEnum;
import com.imooc.springboot.dubbo.nilinili.res.ResultFactory;
import com.imooc.springboot.dubbo.nilinili.service.CategoryService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
@RequestMapping("/category")
@Validated
public class CategoryController {

    @Reference
    private CategoryService categoryService;

    @GetMapping("/selectSons")
    public String SelectAllSonsByName(@RequestParam("name") String name) {
        return categoryService.SelectAllSonsByName(name);
    }

    @GetMapping("/selectCategoryId/{name}")
    public String SelectCategoryIdByName(@PathVariable("name") String name) {
        return ResultFactory.createResult(CodeEnum.SUCCESS,"查询成功",categoryService. selectIdByName(name));
    }

}
